/* GUI CONVERTED from ececd4mt.p (converter v1.76) Thu May  8 00:26:23 2003 */
/* ececd4mt.p - ADD/EDIT/DEACTIVATE ECD4_DETAIL MAINTENANCE             */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.11.1.6 $                                                         */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 8.6  LAST MODIFIED: 07/08/96   CREATED BY: M.Kutwal  *K00C**/
/* REVISION: 8.6  LAST MODIFIED: 03/31/97           BY: Joe Gawel *K09B**/
/* REVISION: 8.6  LAST MODIFIED: 04/17/97           BY: Joe Gawel *K0BV**/
/* REVISION: 8.6  LAST MODIFIED: 06/19/97           BY: Joe Gawel *K0FB**/
/* REVISION: 8.6  LAST MODIFIED: 07/07/97           BY: Joe Gawel *K0F4**/
/* REVISION: 8.6  LAST MODIFIED: 07/18/97           BY: Amy Esau  *K0GM**/
/* REVISION: 8.6  LAST MODIFIED: 01/12/98   BY: *H1G3*  Manmohan Pardesi      */

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/14/00 BY: *N0KW* Jacolyn Neder        */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.11.1.6 $     BY: Karan Motwani         DATE: 04/29/03  ECO: *N2DZ*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*K0F4*  THE INCLUDE FILES USED FOR THIS PATCH (ECRODEF.I, ECROGET.I    */
/*K0F4*  AND ECROPUT.I) SHOULD BE REMOVED ONCE THE NEW FIELDS HAVE BEEN */
/*K0F4*  ADDED TO THE ECD2_DET TABLE IN THE SCHEMA.                     */

/* SHARED VARIABLE  DEFINITIONS */
{mfdeclre.i}

/* EXTERNAL LABEL INCLUDE */
{gplabel.i}

/* PARAMETER DEFINITIONS */
{ecmtparm.i}

define new shared variable part like ecd4_part.
define new shared variable cmtindx as integer.

define shared variable global_recid as recid.

define variable routing    like ecd4_routing label "Routing/Procedure" no-undo.
define variable operation  like ecd4_op no-undo.
define variable nbr        like ecd4_nbr no-undo.
define variable seq        like ecd4_sequence label "Number" no-undo.
define variable del-yn     like mfc_logical initial no no-undo.
define variable deact      as logical label "Deactivate" initial no no-undo.
define variable cmmt       as logical label "Comments" no-undo.
define variable ecd4_recno as recid no-undo.

define buffer ipddet for ipd_det.

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
part    colon 19 pt_desc1 format "x(40)" colon 39 no-label skip
   routing colon 19 ro_desc  format "x(40)" colon 39 no-label skip
   operation colon 19 skip
   seq       colon 19
 SKIP(.4)  /*GUI*/
with frame mt1 width 80 side-labels NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-mt1-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame mt1 = F-mt1-title.
 RECT-FRAME-LABEL:HIDDEN in frame mt1 = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame mt1 =
  FRAME mt1:HEIGHT-PIXELS - RECT-FRAME:Y in frame mt1 - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME mt1 = FRAME mt1:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame mt1:handle).

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
deact           colon 19
   ecd4_sequence   colon 19 label "Number"
   ecd4_property   colon 19 format "x(40)" label "Characteristic"
   ecd4_attribute  colon 19 format "x(40)"
   ecd4_testmthd   colon 19
   ecd4_spec_det   colon 19 format "x(40)"
   ecd4_propertyum colon 19 label "Measure"

   cmmt            colon 19
 SKIP(.4)  /*GUI*/
with frame mt2 width 80 attr-space side-labels NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-mt2-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame mt2 = F-mt2-title.
 RECT-FRAME-LABEL:HIDDEN in frame mt2 = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame mt2 =
  FRAME mt2:HEIGHT-PIXELS - RECT-FRAME:Y in frame mt2 - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME mt2 = FRAME mt2:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame mt2:handle).

global_lang = global_user_lang.

for first ecm_mstr
   fields (ecm_nbr)
   where recid(ecm_mstr) = ecm_recid
no-lock:
end. /* FOR FIRST ecm_mstr ... */

if not available ecm_mstr
then
   return.
else
   nbr = ecm_nbr.

ecd4_recno = ?.

mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


   view frame mt1.
   view frame mt2.

   update
      part
      routing
      operation
      seq
   with frame mt1
   editing:
      if frame-field = "part"
      then do:

         recno = ecd4_recno.
         {mfnp06.i ecd4_det ecd4_part_seq "ecd4_nbr = nbr"
            ecd4_part "input part" ecd4_part "input part"}

         if recno <> ?
         then do:
            part = ecd4_part.
            display
               ecd4_part @ part
               ecd4_routing @ routing
               ecd4_op  @ operation
               ecd4_seq @ seq
            with frame mt1.

            for first pt_mstr
               fields (pt_desc1 pt_part)
               where pt_part = input part
            no-lock :
               display pt_desc1 with frame mt1.
            end. /* FOR FIRST pt_mstr */

            display
               ecd4_seq
               ecd4_property
               ecd4_attribute
               ecd4_testmthd
               ecd4_spec_det
               ecd4_propertyum
            with frame mt2.

            if ecd4_cmtindx <> 0
            then
               cmmt = yes.
            else
               cmmt = no.

            display cmmt with frame mt2.

            assign
               ecd4_recno = recno.
               recno      = ?.
         end. /* IF recno <> ? THEN DO: */
      end. /* IF frame-field = "part" */

      else
         if frame-field = "routing"
         then do:

            recno = ecd4_recno.
            {mfnp06.i ecd4_det ecd4_part_seq "ecd4_part = input part and
            ecd4_nbr = nbr" ecd4_routing "input routing"
            ecd4_routing "input routing"}

            if recno <> ?
            then do:
               assign
                  part    = ecd4_part
                  routing = ecd4_routing.

               display
                  ecd4_part    @ part
                  ecd4_routing @ routing
                  ecd4_op      @ operation
                  ecd4_seq     @ seq
               with frame mt1.

               for first pt_mstr
                  fields (pt_desc1 pt_part)
                  where pt_part = part
               no-lock:
                  display pt_desc1 with frame mt1.
               end. /* FOR FIRST pt_mstr */

               display
                  ecd4_seq
                  ecd4_property
                  ecd4_attribute
                  ecd4_testmthd
                  ecd4_spec_det
                  ecd4_propertyum
               with frame mt2.

               if ecd4_cmtindx <> 0
               then
                  cmmt = yes.
               else
                  cmmt = no.

               display cmmt with frame mt2.

               assign
                  ecd4_recno = recno
                  recno      = ?.
            end. /* IF recno <> ? THEN DO: */
         end. /* IF frame-field = "routing" */

         else
            if frame-field = "operation"
            then do:

               recno = ecd4_recno.
               {mfnp06.i ecd4_det ecd4_part_seq
                "ecd4_part = input part and ecd4_nbr = nbr and
                 ecd4_routing = (if input routing <> """" then
                 input routing else input part)"
                 ecd4_op "input operation"
                 ecd4_op "input operation"}

               if recno <> ?
               then do:
                  assign
                     part      = ecd4_part
                     routing   = ecd4_routing
                     operation = ecd4_op
                     seq       = ecd4_seq.
                  display
                     ecd4_part    @ part
                     ecd4_routing @ routing
                     ecd4_op      @ operation
                     ecd4_seq     @ seq
                  with frame mt1.

                  for first pt_mstr
                     fields (pt_desc1 pt_part)
                     where pt_part = part
                  no-lock:
                     display pt_desc1 with frame mt1.
                  end. /* FOR FIRST pt_mstr */

                  display
                     ecd4_seq
                     ecd4_property
                     ecd4_attribute
                     ecd4_testmthd
                     ecd4_spec_det
                     ecd4_propertyum
                  with frame mt2.

                  if ecd4_cmtindx <> 0
                  then
                     cmmt = yes.
                  else
                     cmmt = no.

                  display cmmt with frame mt2.

                  assign
                     ecd4_recno = recno
                     recno      = ?.
               end. /* IF recno <> ? THEN DO: */
            end. /* IF frame-field = "operation" */

            else
               if frame-field = "seq"
               then do:

                  recno = ecd4_recno.
                  {mfnp06.i ecd4_det ecd4_part_seq
                   "ecd4_part = input part and ecd4_nbr = nbr and
                    ecd4_routing = (if input routing <> """" then
                    input routing else input part)"
                    ecd4_sequence "input seq"
                    ecd4_sequence "input seq" }

                  if recno <> ?
                  then do:
                     assign
                        part      = ecd4_part
                        routing   = ecd4_routing
                        operation = ecd4_op
                        seq       = ecd4_sequence.

                     display
                        ecd4_part    @ part
                        ecd4_routing @ routing
                        ecd4_op      @ operation
                        ecd4_seq     @ seq
                     with frame mt1.

                     for first pt_mstr
                        fields (pt_desc1 pt_part)
                        where pt_part = part
                     no-lock:
                        display pt_desc1 with frame mt1.
                     end. /* FOR FIRST pt_mstr */

                     display
                        ecd4_seq
                        ecd4_property
                        ecd4_attribute
                        ecd4_testmthd
                        ecd4_spec_det
                        ecd4_propertyum
                     with frame mt2.

                     if ecd4_cmtindx <> 0
                     then
                        cmmt = yes.
                     else
                        cmmt = no.

                     display cmmt with frame mt2.

                     assign
                        ecd4_recno = recno
                        recno      = ?.
                  end. /* IF recno <> ? THEN DO: */
               end. /* IF frame-field = "seq" */

               else do:
                  readkey.
                  apply lastkey.
               end. /* ELSE DO */

      if recno <> ?
      then do:
         assign
            part = ecd4_part
            routing = ecd4_routing
            operation = ecd4_op
            seq = ecd4_sequence.

         display
            ecd4_part    @ part
            ecd4_routing @ routing
            ecd4_op      @ operation
            ecd4_seq     @ seq
         with frame mt1.

         for first pt_mstr
            fields (pt_desc1 pt_part)
            where pt_part = part
            no-lock:
               display pt_desc1 with frame mt1.
         end. /* FOR FIRST pt_mstr */

         display
            ecd4_seq
            ecd4_property
            ecd4_attribute
            ecd4_testmthd
            ecd4_spec_det
            ecd4_propertyum
            (if ecd4__qadc01 = "yes" then yes else no) @ deact
         with frame mt2.
         assign
            deact.

         if ecd4_cmtindx <> 0
         then
            cmmt = yes.
         else
            cmmt = no.

         display cmmt with frame mt2.
      end. /* IF recno <> ? */

   end. /* EDITING */

   assign
      part
      routing
      operation
      seq.

   for first pt_mstr
      fields (pt_desc1 pt_part)
      where pt_part = part
   no-lock:
   end. /* FOR FIRST pt_mstr ... */

   if not available pt_mstr
   then do:
      /* ITEM NUMBER DOES NOT EXIST */
      {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3}
      next-prompt part with frame mt1.
      undo, retry.
   end. /* IF NOT available pt_mstr */

   display pt_desc1 with frame mt1.

   if routing = ""
   then
      routing = part.

   for first ro_det
      fields (ro_desc ro_routing)
      where ro_routing = routing
   no-lock:
   end. /* FOR FIRST ro_det ... */

   if not available ro_det
   then do:
      /* ROUTING DOES NOT EXIST */
      {pxmsg.i &MSGNUM=126 &ERRORLEVEL=3}
      next-prompt routing with frame mt1.
      undo, retry.
   end. /* IF NOT AVAILABLE ro_det */

   display ro_desc with frame mt1.

   find first ecd4_det
      where ecd4_part    = input part and
            ecd4_routing = input routing and
            ecd4_op      = input operation and
            ecd4_nbr     = nbr and
            ecd4_seq     = input seq
   exclusive-lock no-error.

   if not available ecd4_det
   then do:
      create ecd4_det.
      assign
         ecd4_nbr      = nbr
         ecd4_part     = part
         ecd4_op       = operation
         ecd4_routing  = routing
         ecd4_sequence = seq.
      if recid(ecd4_det) = -1 then.

      /* ADDING NEW RECORD  */
      {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
   end. /* IF NOT AVAILABLE ecd4_det */
   else do:
      /* MODIFYING EXISTING RECORD */
      {pxmsg.i &MSGNUM=10 &ERRORLEVEL=1}
   end. /* ELSE DO */

   ecd4_recno = recid(ecd4_det).

   /* CHECK TO SEE IF RECORD HAS BEEN DEACTIVATED */
   for first ipd_det
      fields(ipd_end ipd_op ipd_part
             ipd_routing ipd_start ipd_test)
      where ipd_part    = ecd4_part and
            ipd_routing = ecd4_routing and
            ipd_op      = ecd4_op and
            ipd_test    = ecd4_seq
      no-lock:
   end. /* FOR FIRST ipd_det ... */

   if available ipd_det
      and not((ipd_start = ?
              or ipd_start <= today)
             and (ipd_end > today
              or ipd_end = ?))
   then do:

      /* RECORD HAS BEEN DEACTIVATED */
      {pxmsg.i &MSGNUM=5639 &ERRORLEVEL=3}
      next-prompt part.
      undo, retry.
   end. /* IF AVAIL ipd_det */

   display
      ecd4_part    @ part
      ecd4_routing @ routing
      ecd4_op      @ operation
      ecd4_seq     @ seq
   with frame mt1.

   display
      ecd4_seq
      ecd4_property
      ecd4_attribute
      ecd4_testmthd
      ecd4_spec_det
      ecd4_propertyum
      (if ecd4__qadc01 = "yes" then yes else no) @ deact
   with frame mt2.

   if ecd4_cmtindx <> 0
   then
      cmmt = yes.
   else
      cmmt = no.

   display cmmt with frame mt2.

   /* UPDATE frame mt2 */
   ststatus = stline[2].
   status input ststatus.
   del-yn = no.
   assign deact.

   do with frame mt2 on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

      update
         deact.

      update
         ecd4_seq
         when (not deact)
         ecd4_property
         when (not deact)
         ecd4_attribute
         when (not deact)
         ecd4_testmthd
         when (not deact)
         ecd4_spec_det
         when (not deact)
         ecd4_propertyum
         when (not deact)

         cmmt.

      /* DEACTIVATE: */
      if deact = yes
      then
         ecd4__qadc01 = "yes".
      else
         ecd4__qadc01 = "no".

      if cmmt
      then do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         hide frame mt2 no-pause.

         /*NEED TO INITIALIZE CMTINDX, OTHERWISE WE MIGHT GET*/
         /*JUNK VALUES FOR OUR NEW CMT_INDX NUMBER           */
         cmtindx = ecd4_cmtindx.
         {gprun.i ""gpcmmt01.p"" "(input ""ecd4_det"")"}
/*GUI*/ if global-beam-me-up then undo, leave.


         assign
            ecd4_cmtindx = cmtindx
            global_ref   = "".
         view frame mt1.
         view frame mt2.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* IF cmmt THEN DO ON ERROR ...*/
   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* DO WITH FRAME mt2. */
end.  /* MAINLOOP: REPEAT: */
